using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;

using Peradigm.Framework.Domain.Parties;

using Liberty.Domain.GrantManagement;
using Liberty.Domain.ServiceMemberManagement;
using Liberty.Persistence.GrantManagement;
using Liberty.Persistence.Kernel;

using Microsoft.VisualStudio.TestTools.UnitTesting;
//using NUnit.Framework.SyntaxHelpers;

namespace Tests.PersistenceTests.GrantManagement
{
    [TestClass()]
    public class GrantBrokerTests
    {
        #region Constants
        private const string 
            MSG_INVALID_GRANT_TYPES = "Grant types collection was not the correct size.",
            MSG_FOUND_INCORRECT_GRANT_TYPE = "ReferenceValue with incorrect ID was retrieved during the test.";
        #endregion

        #region Properties
        protected string ConnectionString
        {
            get
            {
                return ConfigurationSettings.AppSettings[CONNECTION_STRING];
            }
        }
        #endregion

        #region Setup and Teardown GrantTests
        [TestInitialize()]
        public void SetupGrantTests()
        {
        }

        [TestCleanup()]
        public void TeardownGrantTests()
        {
        }
        #endregion

        #region Test Methods

        [TestMethod()]
        public void TestGrantsMatching()
        {
            GrantSearchCriteria criteria = new GrantSearchCriteria( TEST_OID );
            GrantBroker broker = new GrantBroker( this.ConnectionString );
            List<Grant> grants = broker.GrantsMatching( criteria );
            Assert.AreEqual( 1, grants.Count );
        }

        [TestMethod()]
        public void TestGrantsForServiceMember()
        {
            PersonBroker personBroker = new PersonBroker( this.ConnectionString );
            ServiceMember serviceMember = personBroker.ServiceMemberWith( TEST_SERVICE_MEMBER_ID );
            GrantBroker broker = new GrantBroker( this.ConnectionString );
            List<Grant> grants = broker.GrantsFor( serviceMember );
            Assert.IsTrue( grants.Count > 0 );
        }

        [TestMethod()]
        public void TestGrantTypeCaching()
        {
            GrantBroker broker = new GrantBroker( this.ConnectionString );
            List<GrantType> types = broker.GrantTypes();
            Assert.AreEqual( 4, types.Count, MSG_INVALID_GRANT_TYPES );
        }
        #endregion

        #region Support Methods
        #endregion

        #region Data Elements
        #endregion

        #region Constants
        private const string CONNECTION_STRING = "ConnectionString";

        private const long
            TEST_OID = 1,
            TEST_SERVICE_MEMBER_ID = 12;

        #endregion
    }
}
